<template>
  <div class="common-card" :class="[shadow, { 'is-border': border }]">
    <div class="common-card-header" v-if="$slots.header || title">
      <slot name="header">
        <div class="common-card-title">{{ title }}</div>
      </slot>
      <div class="common-card-extra" v-if="$slots.extra">
        <slot name="extra"></slot>
      </div>
    </div>
    <div class="common-card-body" :style="bodyStyle">
      <slot></slot>
    </div>
    <div class="common-card-footer" v-if="$slots.footer">
      <slot name="footer"></slot>
    </div>
  </div>
</template>

<script setup>
defineProps({
  title: {
    type: String,
    default: ''
  },
  shadow: {
    type: String,
    default: 'always',
    validator: (value) => ['always', 'hover', 'never'].includes(value)
  },
  border: {
    type: Boolean,
    default: true
  },
  bodyStyle: {
    type: [String, Object],
    default: ''
  }
})
</script>

<style lang="scss" scoped>
.common-card {
  background: var(--el-bg-color-overlay);
  border-radius: var(--el-border-radius-base);
  transition: var(--el-transition-all);
  
  &.is-border {
    border: 1px solid var(--el-border-color-light);
  }
  
  &.always {
    box-shadow: var(--el-box-shadow-light);
  }
  
  &.hover {
    &:hover {
      box-shadow: var(--el-box-shadow-light);
    }
  }
  
  &.never {
    box-shadow: none;
  }
  
  .common-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid var(--el-border-color-lighter);
    
    .common-card-title {
      font-size: 16px;
      font-weight: 500;
      color: var(--el-text-color-primary);
    }
    
    .common-card-extra {
      color: var(--el-text-color-secondary);
    }
  }
  
  .common-card-body {
    padding: 20px;
  }
  
  .common-card-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--el-border-color-lighter);
  }
}
</style>